﻿using System;

namespace RexToy.UI.Controls
{
    public class IconButton : ButtonBase
    {
        private DomNode _iconNode;

        public IconButton(string text, IconPosition? position)
            : base(text)
        {
            var pos = position ?? RexToy.UI.Controls.IconPosition.Left;

            this.__domNode.AppendClass(StringExt.Format("ui-btn-icon-{0}", pos));
            var dom = this.__domNode.SearchByName("spn");
            this._iconNode = RexToy.UI.Controls.DomNode.Create(new DomNodeCreateOptions()
            {
                tag = Tag.Span,
                className = "ui-icon ui-icon-shadow"
            });
            this._iconNode.AppendClass(this._iconClass);
            dom.AppendChild(this._iconNode);
        }

        private string _iconClass = "ui-icon-check";
        public string IconClass
        {
            get { return _iconClass; }
            set
            {
                this._iconNode.ReplaceClass(this._iconClass, value);
                _iconClass = value;
            }
        }
    }
}
